class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def findMode(self, root: TreeNode):
        base=0
        count=0
        maxcount=0
        result=[]
        def update(val):
            nonlocal base,count,maxcount,result
            if val!=base:
                if count>maxcount:
                    result=[val]
                elif count==maxcount:
                    result.append(val)
                base=val
                count=0
            else:
                count+=1
        cur=root
        while cur:
            if cur.left is None:
                update(cur.val)
                cur=cur.right
                continue
            pre=cur
            cur=cur.left



